﻿#include "mongodb_bulk_data.h"

void MongoDbBulkData::BulkOptRemove(const std::string &id, const std::string &queryString)
{
	m_datas[id].emplace_back(
		S_RedisDataType{ e_bulkopt_remove, queryString ,"" }
	);
}

void MongoDbBulkData::BulkOptInsert(const std::string &id, const std::string &docString)
{
	m_datas[id].emplace_back(
		S_RedisDataType{ e_bulkopt_insert, "" ,docString }
	);
}

void MongoDbBulkData::BulkOptUpdate(const std::string &id, const std::string &queryString, const std::string &docString)
{
	m_datas[id].emplace_back(
		S_RedisDataType{ e_bulkopt_update, queryString ,docString }
	);
}

void MongoDbBulkData::BuikOptReplace(const std::string &id, const std::string &queryString, const std::string &docString)
{
	m_datas[id].emplace_back(
		S_RedisDataType{ e_bulkopt_replace, queryString ,docString }
	);
}

RedisDataTypeVector &MongoDbBulkData::GetData(const std::string &id)
{
	static RedisDataTypeVector g_empty_data;
	auto it = m_datas.find(id);
	if (it != m_datas.end())
	{
		return it->second;
	}
	return g_empty_data;
}

void MongoDbBulkData::RemoveData(const std::string &id)
{
	m_datas.erase(id);
}

unsigned MongoDbBulkData::GetDataState(const std::string &id)
{
	auto it = m_dataState.find(id);
	if (it != m_dataState.end())
	{
		return it->second;
	}
	return e_bulkopt_state_idle;
}

void MongoDbBulkData::SetDataState(const std::string &id, unsigned state)
{
	m_dataState[id] = state;
}